import { IFormItemConfig, TFormItemType } from "../type";

export const getComponentConfig = (formItemConfig: IFormItemConfig) => {
    const { colSpan, name, label, required, type, placeholder, maxRows, minRows, optionsType, ...rest } = formItemConfig;
    const componentConfig: any = rest
    if (maxRows) componentConfig.autoSize = { minRows, maxRows }
    if (type === "Select") {
        componentConfig.showSearch = true;
        componentConfig.optionFilterProp = "label";
        componentConfig.allowClear = true;
        if (formItemConfig.optionsType === 1) {
            componentConfig.options = formItemConfig.options?.map((item) => ({ value: item, label: item }))
        } else {
            // 获取下拉数据
            componentConfig.options = formItemConfig.options?.map((item: any) => ({ value: item?.id, label: item?.label }))
        }
    } else if (type === "InputNumber") {
        componentConfig.controls = false;
    }
    return componentConfig
}

export const getDefaultComponentConfig = (type: TFormItemType) => {
    if (type === "InputNumber") return {
        precision: 2,
    }
    return {}
}